import { UC } from '@/api/config/servicePort'
import http from '@/api'
import { ResPage, TreeNode, AreaNode } from '@/api/interface'
import { Area } from './interface'

// 获取列表
export const listAreaNode = (id?: string) => {
  return http.get<AreaNode[]>(UC + `/area/node/list`, { id }, { loading: false })
}

// 树型菜单
export function listAreaTable(query?: Area.Query) {
  return http.get<ResPage<TreeNode>>(UC + '/area/table', query ? query : { pageable: false })
}

// 获取列表
export const areaTree = (id?: string) => {
  return http.get(UC + `/area/select/tree`, { id })
}

// 新增
export const addArea = (params: Partial<Area.Form>) => {
  return http.post(UC + `/area`, params)
}

// 编辑
export const updateArea = (params: Partial<Area.Form>) => {
  return http.put(UC + '/area', params)
}
// 删除
export const removeArea = (id: string) => {
  return http.delete(UC + `/area`, { id })
}

// 详情
export const getArea = (id: string) => {
  return http.get<Partial<Area.Form>>(UC + '/area', { id }, { loading: false })
}

// 新增表单默认值
export const getDefault = (parentId: string) => {
  return http.get<Partial<Area.Default>>(UC + '/area/default', { parentId }, { loading: false })
}

// 检查编码是否存在
export function checkExist(newId?: string) {
  return http.get<boolean>(UC + '/area/exist', { newId }, { loading: false })
}
